From be6806f5677f42ed68e5c278823658c543c48ca6 Mon Sep 17 00:00:00 2001 From: Goncalo Gomes Date: Tue, 15 May 2012 15:41:53 +0100 Subject: [PATCH] xl: Introduce vncviewer xm compatibility options Signed-off-by: Goncalo Gomes Committed-by: Ian Campbell --- docs/man/xl.cfg.pod.5 | 4 +++ docs/man/xl.pod.1 | 18 ++++++++++ tools/libxl/xl_cmdimpl.c | 71 ++++++++++++++++++++++++++++++++------- tools/libxl/xl_cmdtable.c | 15 ++++++--- 4 files changed, 91 insertions(+), 17 deletions(-) diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5 index 832bae4cb9..dbe3291197 100644 --- a/docs/man/xl.cfg.pod.5 +++ b/docs/man/xl.cfg.pod.5 @@ -91,6 +91,10 @@ The following options apply to guests of any type. Specifies the UUID of the domain. If not specified, a fresh unique UUID will be generated. +=item B + +Automatically spawn a vncviewer when creating/restoring a guest + =item B Put the guest's vcpus into the named cpu pool. diff --git a/docs/man/xl.pod.1 b/docs/man/xl.pod.1 index b192efadf6..a838f54495 100644 --- a/docs/man/xl.pod.1 +++ b/docs/man/xl.pod.1 @@ -126,6 +126,14 @@ Use the given configuration file. Leave the domain paused after it is created. +=item B<-V>, B<--vncviewer> + +Attach to domain's VNC server, forking a vncviewer process. + +=item B<-A>, B<--vncviewer-autopass> + +Pass VNC password to vncviewer via stdin. + =item B<-c> Attach console to the domain as soon as it has started. This is @@ -439,6 +447,16 @@ See the corresponding option of the I subcommand. Enable debug messages. +=item B<-V>, B<--vncviewer> + +Attach to domain's VNC server, forking a vncviewer process. + +=item B<-A>, B<--vncviewer-autopass> + +Pass VNC password to vncviewer via stdin. + + + =back =item B [I] I I [I] diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 073ab6f03f..dc4d61b814 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -129,6 +129,8 @@ struct domain_create { int paused; int dryrun; int quiet; + int vnc; + int vncautopass; int console_autoconnect; const char *config_file; const char *extra_config; /* extra config string */ @@ -206,9 +208,8 @@ static void find_domain(const char *p) common_domname = was_name ? p : libxl_domid_to_name(ctx, domid); } -static int vncviewer(const char *domain_spec, int autopass) +static int vncviewer(uint32_t domid, int autopass) { - find_domain(domain_spec); libxl_vncviewer_exec(ctx, domid, autopass); fprintf(stderr, "Unable to execute vncviewer\n"); return 1; @@ -551,7 +552,9 @@ vcpp_out: static void parse_config_data(const char *configfile_filename_report, const char *configfile_data, int configfile_len, - libxl_domain_config *d_config) + libxl_domain_config *d_config, + struct domain_create *dom_info) + { const char *buf; long l; @@ -773,6 +776,13 @@ static void parse_config_data(const char *configfile_filename_report, if (!xlu_cfg_get_long(config, "rtc_timeoffset", &l, 0)) b_info->rtc_timeoffset = l; + if (dom_info && !xlu_cfg_get_long(config, "vncviewer", &l, 0)) { + /* Command line arguments must take precedence over what's + * specified in the configuration file. */ + if (!dom_info->vnc) + dom_info->vnc = l; + } + xlu_cfg_get_defbool(config, "localtime", &b_info->localtime, 0); if (!xlu_cfg_get_long (config, "videoram", &l, 0)) @@ -1550,6 +1560,7 @@ static int create_domain(struct domain_create *dom_info) int daemonize = dom_info->daemonize; int monitor = dom_info->monitor; int paused = dom_info->paused; + int vncautopass = dom_info->vncautopass; const char *config_file = dom_info->config_file; const char *extra_config = dom_info->extra_config; const char *restore_file = dom_info->restore_file; @@ -1673,7 +1684,7 @@ static int create_domain(struct domain_create *dom_info) if (!dom_info->quiet) printf("Parsing config file %s\n", config_file); - parse_config_data(config_file, config_data, config_len, &d_config); + parse_config_data(config_file, config_data, config_len, &d_config, dom_info); if (migrate_fd >= 0) { if (d_config.c_info.name) { @@ -1785,6 +1796,9 @@ start: if (!daemonize && !monitor) goto out; + if (dom_info->vnc) + vncviewer(domid, vncautopass); + if (need_daemon) { char *fullname, *name; pid_t child1, got_child; @@ -1911,7 +1925,7 @@ start: libxl_domain_config_dispose(&d_config); libxl_domain_config_init(&d_config); parse_config_data(config_file, config_data, config_len, - &d_config); + &d_config, dom_info); /* * XXX FIXME: If this sleep is not there then domain @@ -2263,7 +2277,9 @@ int main_vncviewer(int argc, char **argv) return 2; } - if (vncviewer(argv[optind], autopass)) + find_domain(argv[optind]); + + if (vncviewer(domid, autopass)) return 1; return 0; } @@ -2538,7 +2554,7 @@ static void list_domains_details(const libxl_dominfo *info, int nb_domain) continue; CHK_ERRNO(asprintf(&config_file, "", info[i].domid)); libxl_domain_config_init(&d_config); - parse_config_data(config_file, (char *)data, len, &d_config); + parse_config_data(config_file, (char *)data, len, &d_config, NULL); printf_info(default_output_format, info[i].domid, &d_config); libxl_domain_config_dispose(&d_config); free(data); @@ -3088,13 +3104,26 @@ int main_restore(int argc, char **argv) const char *config_file = NULL; struct domain_create dom_info; int paused = 0, debug = 0, daemonize = 1, monitor = 1, - console_autoconnect = 0; + console_autoconnect = 0, vnc = 0, vncautopass = 0; int opt, rc; + int option_index = 0; + static struct option long_options[] = { + {"vncviewer", 0, 0, 'V'}, + {"vncviewer-autopass", 0, 0, 'A'}, + {0, 0, 0, 0} + }; + + while (1) { + opt = getopt_long(argc, argv, "FhcpdeVA", long_options, &option_index); + if (opt == -1) + break; - while ((opt = def_getopt(argc, argv, "Fcpde", "restore", 1)) != -1) { switch (opt) { case 0: case 2: return opt; + case 'h': + help("restore"); + return 2; case 'c': console_autoconnect = 1; break; @@ -3111,6 +3140,12 @@ int main_restore(int argc, char **argv) daemonize = 0; monitor = 0; break; + case 'V': + vnc = 1; + break; + case 'A': + vnc = vncautopass = 1; + break; } } @@ -3132,6 +3167,8 @@ int main_restore(int argc, char **argv) dom_info.config_file = config_file; dom_info.restore_file = checkpoint_file; dom_info.migrate_fd = -1; + dom_info.vnc = vnc; + dom_info.vncautopass = vncautopass; dom_info.console_autoconnect = console_autoconnect; dom_info.incr_generationid = 1; @@ -3439,7 +3476,7 @@ int main_create(int argc, char **argv) char extra_config[1024]; struct domain_create dom_info; int paused = 0, debug = 0, daemonize = 1, console_autoconnect = 0, - quiet = 0, monitor = 1; + quiet = 0, monitor = 1, vnc = 0, vncautopass = 0; int opt, rc; int option_index = 0; static struct option long_options[] = { @@ -3447,6 +3484,8 @@ int main_create(int argc, char **argv) {"quiet", 0, 0, 'q'}, {"help", 0, 0, 'h'}, {"defconfig", 1, 0, 'f'}, + {"vncviewer", 0, 0, 'V'}, + {"vncviewer-autopass", 0, 0, 'A'}, {0, 0, 0, 0} }; @@ -3456,7 +3495,7 @@ int main_create(int argc, char **argv) } while (1) { - opt = getopt_long(argc, argv, "Fhnqf:pcde", long_options, &option_index); + opt = getopt_long(argc, argv, "Fhnqf:pcdeVA", long_options, &option_index); if (opt == -1) break; @@ -3489,6 +3528,12 @@ int main_create(int argc, char **argv) case 'q': quiet = 1; break; + case 'V': + vnc = 1; + break; + case 'A': + vnc = vncautopass = 1; + break; default: fprintf(stderr, "option `%c' not supported.\n", optopt); break; @@ -3518,6 +3563,8 @@ int main_create(int argc, char **argv) dom_info.config_file = filename; dom_info.extra_config = extra_config; dom_info.migrate_fd = -1; + dom_info.vnc = vnc; + dom_info.vncautopass = vncautopass; dom_info.console_autoconnect = console_autoconnect; dom_info.incr_generationid = 0; @@ -3620,7 +3667,7 @@ int main_config_update(int argc, char **argv) libxl_domain_config_init(&d_config); - parse_config_data(filename, config_data, config_len, &d_config); + parse_config_data(filename, config_data, config_len, &d_config, NULL); if (debug || dryrun_only) printf_info(default_output_format, -1, &d_config); diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index 9d33707544..7012d8464d 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -30,7 +30,10 @@ struct cmd_spec cmd_table[] = { "-n, --dryrun Dry run - prints the resulting configuration\n" " (deprecated in favour of global -N option).\n" "-d Enable debug messages.\n" - "-e Do not wait in the background for the death of the domain." + "-e Do not wait in the background for the death of the domain.\n" + "-V, --vncviewer Connect to the VNC display after the domain is created.\n" + "-A, --vncviewer-autopass\n" + " Pass VNC password to viewer via stdin." }, { "config-update", &main_config_update, 1, 1, @@ -144,10 +147,12 @@ struct cmd_spec cmd_table[] = { &main_restore, 0, 1, "Restore a domain from a saved state", "[options] [] ", - "-h Print this help.\n" - "-p Do not unpause domain after restoring it.\n" - "-e Do not wait in the background for the death of the domain.\n" - "-d Enable debug messages." + "-h Print this help.\n" + "-p Do not unpause domain after restoring it.\n" + "-e Do not wait in the background for the death of the domain.\n" + "-d Enable debug messages.\n" + "-V, --vncviewer Connect to the VNC display after the domain is created.\n" + "-A, --vncviewer-autopass Pass VNC password to viewer via stdin." }, { "migrate-receive", &main_migrate_receive, 0, 1, -- 2.30.2